/*
*************************************************
				Copyagent
	------------------------------------------
	            crawler_lib.h
*************************************************
Semnaturile functiilor din crawler_lib.c
*/

/*
crawler_lib.h
*/
#ifndef CRAWLER_LIB_H
#define CRAWLER_LIB_H

#define MIN_URL_LEN 6
#define MAX_FILENAME_LEN 255

#define FALS 0
#define ADEVARAT 1
#define BUFFER_SIZE 4096
#define FILENAME_LENGTH 1000
#define DB_QUERY_MAX_LEN 3000
#define MAX_PAGINI 500
#define BIOLUP_SIZE 4
#define LUNG_MIN_PROP 10
#define LUNG_MIN_CUV 2
//US = unit separator
#define US 31

#define TAG_NEED_URL 0
#define TAG_DUMMY 1
#define TAG_SEND_URL 2
#define TAG_URL 3



//Lista url-urilor de parcurs
typedef struct URLList
{
	char * url;  //URL to be read
	struct URLList * next; //next URL in list
	struct URLList * prev; //previous URL in list
	int parcurs;

} urlListNode, * TurlListNode;

typedef struct status_eroare
{
	char mesaj[255];
	short eroare; //este ADEVARAT sau FALS
}Status_eroare;

/* 
Citeste lista initiala a link-urilor si initializeaza utlList-ul corespunzator
return value: 0 - in caz de succes ; 1 - altfel
filename: calea relativa la fisierul de configurare
lista: pointer la lista de url-uri
*/
extern int readFile(char * filename, struct URLList * lista);

/*
getNode: scoate din lista urmatorul nod
return: nodul scos
lista: pointer la lista de url-uri
*/
extern urlListNode * getNode(struct URLList * lista);


/*
insertNode: insereaza un nod in lista
url: url-ul de inserat
lista: listaUrl-urilor
*/
extern int insertNode(char * url, struct URLList * lista);


extern urlListNode * getFirstNode(struct URLList * lista);
extern urlListNode * getLastNode(struct URLList * lista);
extern char * scoate_penultimul_url(struct URLList * lista);
extern void debugPrint(int node_rank, char* message);
extern int replaceChars(char * sir, char toReplace, char replacer);
extern char * extrageHostDinURL(char * URL);
extern int parse_buffer(char* buffer, char * url_buffer, char * prop_buffer);
extern char * denumeste_prop_file(char * url, int rank);
extern char * denumeste_link_file(char * url, int rank);
extern char * normalizez_nume_fisier(char * nume);
extern int sparge_link_bufferul(char * buffer, char * url_curent, struct URLList * lista);
extern int sparge_prop_bufferul(char * buffer, FILE * dest_file);
extern char * adauga_rel_la_abs(char * absolut, char * relativ);
extern int extensia_e_valida(char * url);
extern char * canonizeaza_url(char * url);
extern void afiseaza_lista_url(struct URLList * lista);
extern struct status_eroare relativ_din_absolut(char * absolut, char * domeniu, char * relativ);
extern int * apel_lipsa_linkuri(int need_url, struct URLList * lista, int * noduri_fara_url);
extern void broadcast_cerere_linkuri(int * noduri_fara_url, int * message);
extern int trimitere_linkuri(int * message, struct URLList * lista);
extern int message_contains(int*message, int size);
extern int schimb_de_linkuri( struct URLList * nod, struct URLList * listaUrl);
extern int e_url_unic_local(char * url, struct URLList * lista);
extern int e_url_unic_global(char * url);
extern int e_url_unic(char * url,  struct URLList * lista);
extern int contine_caractere_nepermise(char * url);

#endif

